﻿using System.ComponentModel;
using System.Web.Services;
using System;
using Nomad.WebSync.Extensions;
using System.Web.Services.Protocols;

namespace Nomad.WebSync.Service {
    /// <summary>
    /// Service for desktop access of data on server
    /// </summary>
    [WebService(Namespace = "http://www.nomad.com/WebSync")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public partial class Desktop : System.Web.Services.WebService {
        public WebSyncHeader Header;

        private void Authentication() {
            try {
                if (Header == null)
                    throw new Exception("Access Denied");

                if (string.IsNullOrEmpty(Header.Username))
                    throw new Exception("Access Denied");

                if (Context.Cache[Header.Username].ToString() != Header.Session)
                    throw new Exception("Access Denied");
            } catch {
                throw new Exception("Access Denied");
            }
        }

        private string CreateSession(string username) {
            Context.Cache[username] = username.Encrypt();
            return Context.Cache[username].ToString();
        }
    }
}
